{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='game/game_common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">宝箱设置</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="gb_id" value="{$item['gb_id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>
                <input type="hidden" id="p_status" name="p_status" value="{$item['status']}"/>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>宝箱名称</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="name" placeholder="" name="name"  value="{$item['name']}">
                        <span class="help-block">示例：翡翠宝箱 </span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">开宝箱提示语</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="open_tips" placeholder="" name="open_tips"  value="{$item['open_tips']}">
                        <span class="help-block">示例： 恭喜您，获得</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>绑定奖品：</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="p_id">
                                <option value="0" {if empty($item['p_id']) }selected="selected"{/if}>----------默认不显示----------</option>
                                {loop $box_prizes  $val}
                                <option value="{$val['p_id']}" {if $item['p_id'] == $val['p_id'] }selected="selected"{/if}>{$val['p_id']}-{$val['name']}</option>
                                {/loop}
                            </select>

                        </div>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>宝箱类型</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="type" value="0" {if $item['type']==0 || !$item['type']} checked="checked"{/if} type="radio">常规宝箱
                        </label>
                        <label class="radio-inline">
                            <input name="type" value="1" {if $item['type']=='1' } checked="checked"{/if} type="radio">共享宝箱
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">邀请好友到访人数</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="friend_view" placeholder="" name="friend_view"  value="{$item['friend_view']}">
                    </div>
                </div>


                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditLtItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(
        function (){
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改 提交数据
    function addOrEditLtItem() {
        let postUrl = "{php echo createWebUrl('game',array('op'=>'box_update'));}";
        let success_redirect = "{php echo createWebUrl('game',array('op'=>'box_list'));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let res = e.message;
                let code = res.code;
                let msg = res.msg;
                if (code!=200){
                    layer.msg(msg)
                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    // 修改、删除奖品
    function changeOrDelLttInfo(e) {
        let ltt_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        // if (type=='del'){
        //     postUrl = "{php echo createWebUrl('lt_delltitem');}";
        //     layer.msg('您确定删除该奖品吗？',{
        //         btn:['确定','取消'],
        //         yes:function (index) {
        //             $.ajax({
        //                 url:postUrl,
        //                 dataType:'json',
        //                 method:'post',
        //                 data: {ltt_id:ltt_id,themeid:themeid},
        //                 success:function (e) {
        //                     let res = e.message;
        //                     let code = res.code;
        //                     let msg = res.msg;
        //                     if (code!=200){
        //                         layer.msg(msg);
        //                     }else{
        //                         layer.msg(msg);
        //                         location.reload();
        //                     }
        //                 },
        //                 fail:function (err) {
        //                     console.log(err)
        //                 }
        //             });
        //         }
        //     });
        // }
    }
</script>
